package com.itheima.studyssm.controller;

import com.itheima.studyssm.common.GobalConst;
import com.itheima.studyssm.entity.Result;
import com.itheima.studyssm.pojo.User;
import com.itheima.studyssm.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：sean
 * @date ：Created in 2020/9/15
 * @description ：用户控制器
 * @version: 1.0
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * 根据用户名查询用户
	 * @param username 前端参数
	 * @return
	 */
	@GetMapping("/findByUsername")
	public Result findByUsername(String username){
		log.info("[用户控制器-查询用户 username:{}]",username);
		// 调用业务业务对象，完成业务
		User user = userService.findByUsername(username);
		// ....
		// 返回数据
		return  new Result(true, GobalConst.FIND_SUCCESS, GobalConst.ACTION_SUCCESS,user);

	}
}
